home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / batcsh10.zip / lexyy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-12  |  46.4 KB  |  1,809 lines

  1. /* A lexical scanner generated by flex */
  2.  
  3. /* scanner skeleton version:
  4.  * $Header: /usr/fsys/odin/a/vern/flex/RCS/flex.skel,v 2.16 90/08/03 14:09:36 vern Exp $
  5.  */
  6.  
  7. #define FLEX_SCANNER
  8.  
  9. #include <stdio.h>
  10.  
  11.  
  12. /* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */
  13. #ifdef c_plusplus
  14. #ifndef __cplusplus
  15. #define __cplusplus
  16. #endif
  17. #endif
  18.  
  19.  
  20. #ifdef __cplusplus
  21.  
  22. #include <stdlib.h>
  23. #include <osfcn.h>
  24.  
  25. /* use prototypes in function declarations */
  26. #define YY_USE_PROTOS
  27.  
  28. /* the "const" storage-class-modifier is valid */
  29. #define YY_USE_CONST
  30.  
  31. #else    /* ! __cplusplus */
  32.  
  33. #ifdef __STDC__
  34.  
  35. #ifdef __GNUC__
  36. #include <stddef.h>
  37. void *malloc( size_t );
  38. void free( void* );
  39. #else
  40. #include <stdlib.h>
  41. #endif    /* __GNUC__ */
  42.  
  43. #define YY_USE_PROTOS
  44. #define YY_USE_CONST
  45.  
  46. #endif    /* __STDC__ */
  47. #endif    /* ! __cplusplus */
  48.  
  49.  
  50. #ifdef __TURBOC__
  51. #define YY_USE_PROTOS
  52. #define YY_USE_CONST
  53. #endif
  54.  
  55.  
  56. #ifndef YY_USE_CONST
  57. #define const
  58. #endif
  59.  
  60.  
  61. #ifdef YY_USE_PROTOS
  62. #define YY_PROTO(proto) proto
  63. #else
  64. #define YY_PROTO(proto) ()
  65.  
  66. #ifdef __TURBOC__
  67. #include <alloc.h>
  68. #include <io.h>
  69. #else
  70. /* we can't get here if it's an ANSI C compiler, or a C++ compiler,
  71.  * so it's got to be a K&R compiler, and therefore there's no standard
  72.  * place from which to include these definitions
  73.  */
  74. char *malloc();
  75. int free();
  76. int read();
  77. #endif
  78. #endif
  79.  
  80.  
  81. /* amount of stuff to slurp up with each read */
  82. #ifndef YY_READ_BUF_SIZE
  83. #define YY_READ_BUF_SIZE 8192
  84. #endif
  85.  
  86. /* returned upon end-of-file */
  87. #define YY_END_TOK 0
  88.  
  89. /* copy whatever the last rule matched to the standard output */
  90.  
  91. /* cast to (char *) is because for 8-bit chars, yytext is (unsigned char *) */
  92. /* this used to be an fputs(), but since the string might contain NUL's,
  93.  * we now use fwrite()
  94.  */
  95. #define ECHO (void) fwrite( (char *) yytext, yyleng, 1, yyout )
  96.  
  97. /* gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
  98.  * is returned in "result".
  99.  */
  100. #define YY_INPUT(buf,result,max_size) \
  101.     if ( (result = read( fileno(yyin), (char *) buf, max_size )) < 0 ) \
  102.         YY_FATAL_ERROR( "read() in flex scanner failed" );
  103. #define YY_NULL 0
  104.  
  105. /* no semi-colon after return; correct usage is to write "yyterminate();" -
  106.  * we don't want an extra ';' after the "return" because that will cause
  107.  * some compilers to complain about unreachable statements.
  108.  */
  109. #define yyterminate() return ( YY_NULL )
  110.  
  111. /* report a fatal error */
  112.  
  113. /* The funky do-while is used to turn this macro definition into
  114.  * a single C statement (which needs a semi-colon terminator).
  115.  * This avoids problems with code like:
  116.  *
  117.  *     if ( something_happens )
  118.  *        YY_FATAL_ERROR( "oops, the something happened" );
  119.  *    else
  120.  *        everything_okay();
  121.  *
  122.  * Prior to using the do-while the compiler would get upset at the
  123.  * "else" because it interpreted the "if" statement as being all
  124.  * done when it reached the ';' after the YY_FATAL_ERROR() call.
  125.  */
  126.  
  127. #define YY_FATAL_ERROR(msg) \
  128.     do \
  129.         { \
  130.         (void) fputs( msg, stderr ); \
  131.         (void) putc( '\n', stderr ); \
  132.         exit( 1 ); \
  133.         } \
  134.     while ( 0 )
  135.  
  136. /* default yywrap function - always treat EOF as an EOF */
  137. #define yywrap() 1
  138.  
  139. /* enter a start condition.  This macro really ought to take a parameter,
  140.  * but we do it the disgusting crufty way forced on us by the ()-less
  141.  * definition of BEGIN
  142.  */
  143. #define BEGIN yy_start = 1 + 2 *
  144.  
  145. /* action number for EOF rule of a given start state */
  146. #define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
  147.  
  148. /* special action meaning "start processing a new file" */
  149. #define YY_NEW_FILE \
  150.     do \
  151.         { \
  152.         yy_init_buffer( yy_current_buffer, yyin ); \
  153.         yy_load_buffer_state(); \
  154.         } \
  155.     while ( 0 )
  156.  
  157. /* default declaration of generated scanner - a define so the user can
  158.  * easily add parameters
  159.  */
  160. #define YY_DECL int yylex YY_PROTO(( void )) 
  161.  
  162. /* code executed at the end of each rule */
  163. #define YY_BREAK break;
  164.  
  165. #define YY_END_OF_BUFFER_CHAR 0
  166.  
  167. #ifndef YY_BUF_SIZE
  168. #define YY_BUF_SIZE (YY_READ_BUF_SIZE * 2) /* size of default input buffer */
  169. #endif
  170.  
  171. typedef struct yy_buffer_state *YY_BUFFER_STATE;
  172.  
  173. #define YY_CHAR char
  174. #define INITIAL 0
  175. /**************************************************************************/
  176. /*    MODULE: bat2csh.l                                                   */
  177. /*   PURPOSE: converts dos batch files to unix csh files                  */
  178. /*    AUTHOR: Bill Pierpoint                                              */
  179. /*       LEX: FLEX Version 2.3.7                                          */
  180. /*  COMPILER: Borland C Version 3.1                                       */
  181. /* COPYRIGHT: None.  Public Domain.                                       */
  182. /*   VERSION: 1.00                                                        */
  183. /*   RELEASE: January 12, 1994                                            */
  184. /**************************************************************************/
  185. #include <stdc.h>
  186. #ifdef __BORLANDC__
  187. #pragma hdrstop
  188. #endif
  189.  
  190. #define putstr(s)    fputs((s),  stdout)
  191. #define puttab()    fputc('\t', stdout)
  192. #define putln()        fputc('\n', stdout)
  193. #define token(t)    (t)
  194. #define ckeol(t)    do { if((t)==EOL) { puts(" ### SYNTAX ERROR ###"); \
  195.                           errorcount++; return;} } while(0)
  196. #define cktok(t, x)    do { if((t)!=(x)) { puts(" ### SYNTAX ERROR ###"); \
  197.                           errorcount++; eattokens(); return;} } while(0)
  198.  
  199. typedef struct
  200. {
  201.     int token;
  202.     void (*fn)(void);
  203. } FNTBL;
  204.  
  205. #define STRBUFSIZE    129
  206. char textbuf[STRBUFSIZE];
  207.  
  208. /**************************************************************************/
  209. /* token enumeration                                                      */
  210. /**************************************************************************/
  211. enum {
  212.     OTHER=1,
  213.     EOL,
  214.     SPACE,
  215.     VARIABLE,
  216.     PARAMETER,
  217.     WORD,
  218.     INIT_CALL,
  219.     INIT_ECHO,
  220.     INIT_FOR,
  221.     INIT_GOTO,
  222.     INIT_IF,
  223.     INIT_PATH,
  224.     INIT_PAUSE,
  225.     INIT_REM,
  226.     INIT_SET,
  227.     INIT_SHIFT,
  228.     INIT_LABEL,
  229.     INIT_COMMAND,
  230.     ECHO_ON,
  231.     ECHO_OFF,
  232.     ECHO_DOT,
  233.     IF_NOT,
  234.     IF_ERRORLEVEL,
  235.     IF_EXIST,
  236.     FOR_VARIABLE,
  237.     FOR_IN,
  238.     FOR_WORDLIST,
  239.     FOR_DO
  240. };
  241.  
  242. /**************************************************************************/
  243. /* function prototypes                                                    */
  244. /**************************************************************************/
  245. /* support functions */
  246. char *cvt_parameter(char *s);
  247. char *cvt_variable(char *s);
  248. char *cvt_for_variable(char *s);
  249. char *cvt_set_variable(int token);
  250. char *cvt_token(int token, char *s);
  251. int dispatch(void);
  252. void indent(void);
  253. int lex(void);
  254. void putbacktoken(void);
  255. void puttokln(int token, char *start, char *end);
  256. int  reporterrors(void);
  257. void terminate(void);
  258. char *tr(char *s, int oldch, int newch);
  259.  
  260. /* keyword functions */
  261. void kw_call(void);
  262. void kw_command(void);
  263. void kw_echo(void);
  264. void kw_for(void);
  265. void kw_goto(void);
  266. void kw_if(void);
  267. void kw_label(void);
  268. void kw_ln(void);
  269. void kw_path(void);
  270. void kw_pause(void);
  271. void kw_remark(void);
  272. void kw_set(void);
  273. void kw_shift(void);
  274.  
  275. #define ECHOS 1
  276. #define TEXT 2
  277. #define FOR 3
  278.  
  279. /* done after the current pattern has been matched and before the
  280.  * corresponding action - sets up yytext
  281.  */
  282. #define YY_DO_BEFORE_ACTION \
  283.     yytext = yy_bp; \
  284.     yyleng = yy_cp - yy_bp; \
  285.     yy_hold_char = *yy_cp; \
  286.     *yy_cp = '\0'; \
  287.     yy_c_buf_p = yy_cp;
  288.  
  289. #define EOB_ACT_CONTINUE_SCAN 0
  290. #define EOB_ACT_END_OF_FILE 1
  291. #define EOB_ACT_LAST_MATCH 2
  292.  
  293. /* return all but the first 'n' matched characters back to the input stream */
  294. #define yyless(n) \
  295.     do \
  296.         { \
  297.         /* undo effects of setting up yytext */ \
  298.         *yy_cp = yy_hold_char; \
  299.         yy_c_buf_p = yy_cp = yy_bp + n; \
  300.         YY_DO_BEFORE_ACTION; /* set up yytext again */ \
  301.         } \
  302.     while ( 0 )
  303.  
  304. #define unput(c) yyunput( c, yytext )
  305.  
  306.  
  307. struct yy_buffer_state
  308.     {
  309.     FILE *yy_input_file;
  310.  
  311.     YY_CHAR *yy_ch_buf;        /* input buffer */
  312.     YY_CHAR *yy_buf_pos;    /* current position in input buffer */
  313.  
  314.     /* size of input buffer in bytes, not including room for EOB characters*/
  315.     int yy_buf_size;    
  316.  
  317.     /* number of characters read into yy_ch_buf, not including EOB characters */
  318.     int yy_n_chars;
  319.  
  320.     int yy_eof_status;        /* whether we've seen an EOF on this buffer */
  321. #define EOF_NOT_SEEN 0
  322.     /* "pending" happens when the EOF has been seen but there's still
  323.      * some text process
  324.      */
  325. #define EOF_PENDING 1
  326. #define EOF_DONE 2
  327.     };
  328.  
  329. static YY_BUFFER_STATE yy_current_buffer;
  330.  
  331. /* we provide macros for accessing buffer states in case in the
  332.  * future we want to put the buffer states in a more general
  333.  * "scanner state"
  334.  */
  335. #define YY_CURRENT_BUFFER yy_current_buffer
  336.  
  337.  
  338. /* yy_hold_char holds the character lost when yytext is formed */
  339. static YY_CHAR yy_hold_char;
  340.  
  341. static int yy_n_chars;        /* number of characters read into yy_ch_buf */
  342.  
  343.  
  344.  
  345. #ifndef YY_USER_ACTION
  346. #define YY_USER_ACTION
  347. #endif
  348.  
  349. #ifndef YY_USER_INIT
  350. #define YY_USER_INIT
  351. #endif
  352.  
  353. extern YY_CHAR *yytext;
  354. extern int yyleng;
  355. extern FILE *yyin, *yyout;
  356.  
  357. YY_CHAR *yytext;
  358. int yyleng;
  359.  
  360. FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0;
  361.  
  362. #define YY_END_OF_BUFFER 33
  363. typedef int yy_state_type;
  364. static const short int yy_accept[94] =
  365.     {   0,
  366.         0,    0,    0,    0,    0,    0,    0,    0,   33,   31,
  367.        29,   28,   14,   14,   14,   14,   14,   14,   14,   14,
  368.        14,   13,    1,   30,   17,   30,   21,   31,   30,   30,
  369.        31,   31,   31,   31,   29,   14,   14,   14,   14,   14,
  370.         6,   14,   14,   14,   14,   12,   30,   30,   15,   21,
  371.         0,    0,   23,   30,   30,   30,    0,   26,   25,   14,
  372.        14,    4,   14,   14,   14,    8,    9,   14,   16,   22,
  373.        24,   30,   30,   18,   27,    2,    3,    5,   10,   14,
  374.        14,   30,   30,    7,   11,   30,   20,   30,   30,   30,
  375.        30,   19,    0
  376.  
  377.     } ;
  378.  
  379. static const YY_CHAR yy_ec[128] =
  380.     {   0,
  381.         1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
  382.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  383.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  384.         1,    2,    4,    5,    4,    4,    6,    4,    5,    7,
  385.         8,    5,    5,    5,    4,    9,    5,   10,   10,   10,
  386.        10,   10,   10,   10,   10,   10,   10,   11,    2,    5,
  387.         2,    5,    5,   12,   13,    4,   14,   15,   16,   17,
  388.        18,   19,   20,    4,    4,   21,   22,   23,   24,   25,
  389.         4,   26,   27,   28,   29,   30,    4,   31,    4,    4,
  390.         5,    5,    5,    5,    5,    5,   13,    4,   14,   15,
  391.  
  392.        16,   17,   18,   19,   20,    4,    4,   21,   22,   23,
  393.        24,   25,    4,   26,   27,   28,   29,   30,    4,   31,
  394.         4,    4,    4,    5,    4,    4,    1
  395.     } ;
  396.  
  397. static const YY_CHAR yy_meta[32] =
  398.     {   0,
  399.         1,    1,    1,    2,    3,    4,    2,    5,    3,    2,
  400.         3,    3,    2,    2,    2,    2,    2,    2,    2,    2,
  401.         2,    2,    2,    2,    2,    2,    2,    2,    2,    2,
  402.         2
  403.     } ;
  404.  
  405. static const short int yy_base[102] =
  406.     {   0,
  407.         0,   21,   33,   57,   81,  104,  126,  145,  112,  200,
  408.       109,  200,    0,   96,   94,   79,   78,   84,   87,   83,
  409.        21,    0,  200,    0,    0,   21,   96,   35,   17,   72,
  410.        89,    0,   70,   70,   90,    0,   70,   71,   63,   60,
  411.         0,   18,   64,   57,   60,    0,    0,   62,    0,   76,
  412.        71,    0,   70,   49,   54,   45,   64,  200,  200,   50,
  413.        46,    0,   45,   49,   40,    0,    0,   48,    0,  200,
  414.         0,   40,   35,    0,  200,    0,    0,    0,    0,   45,
  415.        28,   29,   26,    0,    0,   32,    0,   36,   21,   34,
  416.        28,    0,  200,  165,  170,  174,  178,  182,  186,  191,
  417.  
  418.       194
  419.     } ;
  420.  
  421. static const short int yy_def[102] =
  422.     {   0,
  423.        93,    1,   94,   94,   94,   94,   95,   95,   93,   93,
  424.        93,   93,   96,   96,   96,   96,   96,   96,   96,   96,
  425.        96,   97,   93,   98,   98,   98,   93,   99,   98,   98,
  426.        93,  100,   93,   93,   93,   96,   96,   96,   96,   96,
  427.        96,   96,   96,   96,   96,   97,   98,   98,   98,   93,
  428.        99,  101,   99,   98,   98,   98,  100,   93,   93,   96,
  429.        96,   96,   96,   96,   96,   96,   96,   96,   98,   93,
  430.       101,   98,   98,   98,   93,   96,   96,   96,   96,   96,
  431.        96,   98,   98,   96,   96,   98,   98,   98,   98,   98,
  432.        98,   98,    0,   93,   93,   93,   93,   93,   93,   93,
  433.  
  434.        93
  435.     } ;
  436.  
  437. static const short int yy_nxt[232] =
  438.     {   0,
  439.        10,   11,   12,   13,   10,   10,   13,   13,   10,   13,
  440.        10,   10,   13,   14,   13,   15,   16,   17,   13,   18,
  441.        13,   13,   13,   13,   19,   20,   21,   13,   13,   13,
  442.        13,   22,   23,   10,   11,   12,   44,   48,   10,   45,
  443.        52,   25,   54,   49,   53,   64,   65,   55,   92,   91,
  444.        90,   89,   88,   87,   86,   85,   26,   10,   11,   12,
  445.        84,   83,   10,   82,   81,   25,   80,   79,   78,   77,
  446.        76,   75,   74,   73,   72,   70,   70,   50,   69,   68,
  447.        26,   10,   27,   12,   67,   66,   28,   63,   62,   61,
  448.        60,   35,   59,   58,   52,   56,   29,   50,   43,   42,
  449.  
  450.        41,   40,   39,   30,   10,   27,   12,   38,   37,   28,
  451.        35,   93,   93,   93,   93,   93,   93,   93,   93,   29,
  452.        93,   93,   93,   93,   93,   93,   30,   11,   12,   93,
  453.        93,   31,   32,   93,   93,   93,   93,   93,   93,   93,
  454.        33,   93,   93,   93,   93,   34,   11,   12,   93,   93,
  455.        31,   32,   93,   93,   93,   93,   93,   93,   93,   33,
  456.        93,   93,   93,   93,   34,   24,   24,   24,   24,   24,
  457.        10,   10,   10,   10,   10,   36,   93,   93,   36,   46,
  458.        93,   93,   46,   47,   47,   93,   47,   51,   93,   51,
  459.        51,   57,   57,   57,   57,   71,   93,   93,   71,    9,
  460.  
  461.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  462.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  463.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  464.        93
  465.     } ;
  466.  
  467. static const short int yy_chk[232] =
  468.     {   0,
  469.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  470.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  471.         1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
  472.         1,    2,    2,    3,    3,    3,   21,   26,    3,   21,
  473.        28,    3,   29,   26,   28,   42,   42,   29,   91,   90,
  474.        89,   88,   86,   83,   82,   81,    3,    4,    4,    4,
  475.        80,   73,    4,   72,   68,    4,   65,   64,   63,   61,
  476.        60,   57,   56,   55,   54,   53,   51,   50,   48,   45,
  477.         4,    5,    5,    5,   44,   43,    5,   40,   39,   38,
  478.        37,   35,   34,   33,   31,   30,    5,   27,   20,   19,
  479.  
  480.        18,   17,   16,    5,    6,    6,    6,   15,   14,    6,
  481.        11,    9,    0,    0,    0,    0,    0,    0,    0,    6,
  482.         0,    0,    0,    0,    0,    0,    6,    7,    7,    0,
  483.         0,    7,    7,    0,    0,    0,    0,    0,    0,    0,
  484.         7,    0,    0,    0,    0,    7,    8,    8,    0,    0,
  485.         8,    8,    0,    0,    0,    0,    0,    0,    0,    8,
  486.         0,    0,    0,    0,    8,   94,   94,   94,   94,   94,
  487.        95,   95,   95,   95,   95,   96,    0,    0,   96,   97,
  488.         0,    0,   97,   98,   98,    0,   98,   99,    0,   99,
  489.        99,  100,  100,  100,  100,  101,    0,    0,  101,   93,
  490.  
  491.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  492.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  493.        93,   93,   93,   93,   93,   93,   93,   93,   93,   93,
  494.        93
  495.     } ;
  496.  
  497. static yy_state_type yy_last_accepting_state;
  498. static YY_CHAR *yy_last_accepting_cpos;
  499.  
  500. /* the intent behind this definition is that it'll catch
  501.  * any uses of REJECT which flex missed
  502.  */
  503. #define REJECT reject_used_but_not_detected
  504. #define yymore() yymore_used_but_not_detected
  505. #define YY_MORE_ADJ 0
  506.  
  507. /* these variables are all declared out here so that section 3 code can
  508.  * manipulate them
  509.  */
  510. /* points to current character in buffer */
  511. static YY_CHAR *yy_c_buf_p = (YY_CHAR *) 0;
  512. static int yy_init = 1;        /* whether we need to initialize */
  513. static int yy_start = 0;    /* start state number */
  514.  
  515. /* flag which is used to allow yywrap()'s to do buffer switches
  516.  * instead of setting up a fresh yyin.  A bit of a hack ...
  517.  */
  518. static int yy_did_buffer_switch_on_eof;
  519.  
  520. static yy_state_type yy_get_previous_state YY_PROTO(( void ));
  521. static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state ));
  522. static int yy_get_next_buffer YY_PROTO(( void ));
  523. static void yyunput YY_PROTO(( YY_CHAR c, YY_CHAR *buf_ptr ));
  524. void yyrestart YY_PROTO(( FILE *input_file ));
  525. void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer ));
  526. void yy_load_buffer_state YY_PROTO(( void ));
  527. YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size ));
  528. void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b ));
  529. void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file ));
  530.  
  531. #define yy_new_buffer yy_create_buffer
  532.  
  533. #ifdef __cplusplus
  534. static int yyinput YY_PROTO(( void ));
  535. #else
  536. static int input YY_PROTO(( void ));
  537. #endif
  538.  
  539. YY_DECL
  540.     {
  541.     register yy_state_type yy_current_state;
  542.     register YY_CHAR *yy_cp, *yy_bp;
  543.     register int yy_act;
  544.  
  545.  
  546.  
  547.     if ( yy_init )
  548.     {
  549.     YY_USER_INIT;
  550.  
  551.     if ( ! yy_start )
  552.         yy_start = 1;    /* first start state */
  553.  
  554.     if ( ! yyin )
  555.         yyin = stdin;
  556.  
  557.     if ( ! yyout )
  558.         yyout = stdout;
  559.  
  560.     if ( yy_current_buffer )
  561.         yy_init_buffer( yy_current_buffer, yyin );
  562.     else
  563.         yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE );
  564.  
  565.     yy_load_buffer_state();
  566.  
  567.     yy_init = 0;
  568.     }
  569.  
  570.     while ( 1 )        /* loops until end-of-file is reached */
  571.     {
  572.     yy_cp = yy_c_buf_p;
  573.  
  574.     /* support of yytext */
  575.     *yy_cp = yy_hold_char;
  576.  
  577.     /* yy_bp points to the position in yy_ch_buf of the start of the
  578.      * current run.
  579.      */
  580.     yy_bp = yy_cp;
  581.  
  582.     yy_current_state = yy_start;
  583.     if ( yy_bp[-1] == '\n' )
  584.         ++yy_current_state;
  585. yy_match:
  586.     do
  587.         {
  588.         register YY_CHAR yy_c = yy_ec[*yy_cp];
  589.         if ( yy_accept[yy_current_state] )
  590.         {
  591.         yy_last_accepting_state = yy_current_state;
  592.         yy_last_accepting_cpos = yy_cp;
  593.         }
  594.         while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  595.         {
  596.         yy_current_state = yy_def[yy_current_state];
  597.         if ( yy_current_state >= 94 )
  598.             yy_c = yy_meta[yy_c];
  599.         }
  600.         yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  601.         ++yy_cp;
  602.         }
  603.     while ( yy_base[yy_current_state] != 200 );
  604.  
  605. yy_find_action:
  606.     yy_act = yy_accept[yy_current_state];
  607.  
  608.     YY_DO_BEFORE_ACTION;
  609.     YY_USER_ACTION;
  610.  
  611. do_action:    /* this label is used only to access EOF actions */
  612.  
  613.  
  614.     switch ( yy_act )
  615.         {
  616.         case 0: /* must backtrack */
  617.         /* undo the effects of YY_DO_BEFORE_ACTION */
  618.         *yy_cp = yy_hold_char;
  619.         yy_cp = yy_last_accepting_cpos;
  620.         yy_current_state = yy_last_accepting_state;
  621.         goto yy_find_action;
  622.  
  623. case 1:
  624. ;
  625.     YY_BREAK
  626. case 2:
  627. return token(INIT_CALL);
  628.     YY_BREAK
  629. case 3:
  630. return token(INIT_ECHO);
  631.     YY_BREAK
  632. case 4:
  633. return token(INIT_FOR);
  634.     YY_BREAK
  635. case 5:
  636. return token(INIT_GOTO);
  637.     YY_BREAK
  638. case 6:
  639. return token(INIT_IF);
  640.     YY_BREAK
  641. case 7:
  642. return token(INIT_PAUSE);
  643.     YY_BREAK
  644. case 8:
  645. return token(INIT_REM);
  646.     YY_BREAK
  647. case 9:
  648. return token(INIT_SET);
  649.     YY_BREAK
  650. case 10:
  651. return token(INIT_PATH);
  652.     YY_BREAK
  653. case 11:
  654. return token(INIT_SHIFT);
  655.     YY_BREAK
  656. case 12:
  657. return token(INIT_LABEL);
  658.     YY_BREAK
  659. case 13:
  660. return token(INIT_REM);
  661.     YY_BREAK
  662. case 14:
  663. return token(INIT_COMMAND);
  664.     YY_BREAK
  665. case 15:
  666. return token(ECHO_ON);
  667.     YY_BREAK
  668. case 16:
  669. return token(ECHO_OFF);
  670.     YY_BREAK
  671. case 17:
  672. return token(ECHO_DOT);
  673.     YY_BREAK
  674. case 18:
  675. return token(IF_NOT);
  676.     YY_BREAK
  677. case 19:
  678. return token(IF_ERRORLEVEL);
  679.     YY_BREAK
  680. case 20:
  681. return token(IF_EXIST);
  682.     YY_BREAK
  683. case 21:
  684. return token(SPACE);
  685.     YY_BREAK
  686. case 22:
  687. return token(VARIABLE);
  688.     YY_BREAK
  689. case 23:
  690. return token(PARAMETER);
  691.     YY_BREAK
  692. case 24:
  693. return token(FOR_VARIABLE);
  694.     YY_BREAK
  695. case 25:
  696. return token(FOR_IN);
  697.     YY_BREAK
  698. case 26:
  699. return token(FOR_DO);
  700.     YY_BREAK
  701. case 27:
  702. return token(FOR_WORDLIST);
  703.     YY_BREAK
  704. case 28:
  705. return token(EOL);
  706.     YY_BREAK
  707. case 29:
  708. ;
  709.     YY_BREAK
  710. case 30:
  711. return token(WORD);
  712.     YY_BREAK
  713. case 31:
  714. return token(OTHER);
  715.     YY_BREAK
  716. case 32:
  717. ECHO;
  718.     YY_BREAK
  719. case YY_STATE_EOF(INITIAL):
  720. case YY_STATE_EOF(ECHOS):
  721. case YY_STATE_EOF(TEXT):
  722. case YY_STATE_EOF(FOR):
  723.     yyterminate();
  724.  
  725.         case YY_END_OF_BUFFER:
  726.         {
  727.         /* amount of text matched not including the EOB char */
  728.         int yy_amount_of_matched_text = yy_cp - yytext - 1;
  729.  
  730.         /* undo the effects of YY_DO_BEFORE_ACTION */
  731.         *yy_cp = yy_hold_char;
  732.  
  733.         /* note that here we test for yy_c_buf_p "<=" to the position
  734.          * of the first EOB in the buffer, since yy_c_buf_p will
  735.          * already have been incremented past the NUL character
  736.          * (since all states make transitions on EOB to the end-
  737.          * of-buffer state).  Contrast this with the test in yyinput().
  738.          */
  739.         if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  740.             /* this was really a NUL */
  741.             {
  742.             yy_state_type yy_next_state;
  743.  
  744.             yy_c_buf_p = yytext + yy_amount_of_matched_text;
  745.  
  746.             yy_current_state = yy_get_previous_state();
  747.  
  748.             /* okay, we're now positioned to make the
  749.              * NUL transition.  We couldn't have
  750.              * yy_get_previous_state() go ahead and do it
  751.              * for us because it doesn't know how to deal
  752.              * with the possibility of jamming (and we
  753.              * don't want to build jamming into it because
  754.              * then it will run more slowly)
  755.              */
  756.  
  757.             yy_next_state = yy_try_NUL_trans( yy_current_state );
  758.  
  759.             yy_bp = yytext + YY_MORE_ADJ;
  760.  
  761.             if ( yy_next_state )
  762.             {
  763.             /* consume the NUL */
  764.             yy_cp = ++yy_c_buf_p;
  765.             yy_current_state = yy_next_state;
  766.             goto yy_match;
  767.             }
  768.  
  769.             else
  770.             {
  771.             goto yy_find_action;
  772.             }
  773.             }
  774.  
  775.         else switch ( yy_get_next_buffer() )
  776.             {
  777.             case EOB_ACT_END_OF_FILE:
  778.             {
  779.             yy_did_buffer_switch_on_eof = 0;
  780.  
  781.             if ( yywrap() )
  782.                 {
  783.                 /* note: because we've taken care in
  784.                  * yy_get_next_buffer() to have set up yytext,
  785.                  * we can now set up yy_c_buf_p so that if some
  786.                  * total hoser (like flex itself) wants
  787.                  * to call the scanner after we return the
  788.                  * YY_NULL, it'll still work - another YY_NULL
  789.                  * will get returned.
  790.                  */
  791.                 yy_c_buf_p = yytext + YY_MORE_ADJ;
  792.  
  793.                 yy_act = YY_STATE_EOF((yy_start - 1) / 2);
  794.                 goto do_action;
  795.                 }
  796.  
  797.             else
  798.                 {
  799.                 if ( ! yy_did_buffer_switch_on_eof )
  800.                 YY_NEW_FILE;
  801.                 }
  802.             }
  803.             break;
  804.  
  805.             case EOB_ACT_CONTINUE_SCAN:
  806.             yy_c_buf_p = yytext + yy_amount_of_matched_text;
  807.  
  808.             yy_current_state = yy_get_previous_state();
  809.  
  810.             yy_cp = yy_c_buf_p;
  811.             yy_bp = yytext + YY_MORE_ADJ;
  812.             goto yy_match;
  813.  
  814.             case EOB_ACT_LAST_MATCH:
  815.             yy_c_buf_p =
  816.                 &yy_current_buffer->yy_ch_buf[yy_n_chars];
  817.  
  818.             yy_current_state = yy_get_previous_state();
  819.  
  820.             yy_cp = yy_c_buf_p;
  821.             yy_bp = yytext + YY_MORE_ADJ;
  822.             goto yy_find_action;
  823.             }
  824.         break;
  825.         }
  826.  
  827.         default:
  828. #ifdef FLEX_DEBUG
  829.         printf( "action # %d\n", yy_act );
  830. #endif
  831.         YY_FATAL_ERROR(
  832.             "fatal flex scanner internal error--no action found" );
  833.         }
  834.     }
  835.     }
  836.  
  837.  
  838. /* yy_get_next_buffer - try to read in a new buffer
  839.  *
  840.  * synopsis
  841.  *     int yy_get_next_buffer();
  842.  *     
  843.  * returns a code representing an action
  844.  *     EOB_ACT_LAST_MATCH - 
  845.  *     EOB_ACT_CONTINUE_SCAN - continue scanning from current position
  846.  *     EOB_ACT_END_OF_FILE - end of file
  847.  */
  848.  
  849. static int yy_get_next_buffer()
  850.  
  851.     {
  852.     register YY_CHAR *dest = yy_current_buffer->yy_ch_buf;
  853.     register YY_CHAR *source = yytext - 1; /* copy prev. char, too */
  854.     register int number_to_move, i;
  855.     int ret_val;
  856.  
  857.     if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] )
  858.     YY_FATAL_ERROR(
  859.         "fatal flex scanner internal error--end of buffer missed" );
  860.  
  861.     /* try to read more data */
  862.  
  863.     /* first move last chars to start of buffer */
  864.     number_to_move = yy_c_buf_p - yytext;
  865.  
  866.     for ( i = 0; i < number_to_move; ++i )
  867.     *(dest++) = *(source++);
  868.  
  869.     if ( yy_current_buffer->yy_eof_status != EOF_NOT_SEEN )
  870.     /* don't do the read, it's not guaranteed to return an EOF,
  871.      * just force an EOF
  872.      */
  873.     yy_n_chars = 0;
  874.  
  875.     else
  876.     {
  877.     int num_to_read = yy_current_buffer->yy_buf_size - number_to_move - 1;
  878.  
  879.     if ( num_to_read > YY_READ_BUF_SIZE )
  880.         num_to_read = YY_READ_BUF_SIZE;
  881.  
  882.     else if ( num_to_read <= 0 )
  883.         YY_FATAL_ERROR( "fatal error - scanner input buffer overflow" );
  884.  
  885.     /* read in more data */
  886.     YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]),
  887.           yy_n_chars, num_to_read );
  888.     }
  889.  
  890.     if ( yy_n_chars == 0 )
  891.     {
  892.     if ( number_to_move == 1 )
  893.         {
  894.         ret_val = EOB_ACT_END_OF_FILE;
  895.         yy_current_buffer->yy_eof_status = EOF_DONE;
  896.         }
  897.  
  898.     else
  899.         {
  900.         ret_val = EOB_ACT_LAST_MATCH;
  901.         yy_current_buffer->yy_eof_status = EOF_PENDING;
  902.         }
  903.     }
  904.  
  905.     else
  906.     ret_val = EOB_ACT_CONTINUE_SCAN;
  907.  
  908.     yy_n_chars += number_to_move;
  909.     yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR;
  910.     yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
  911.  
  912.     /* yytext begins at the second character in yy_ch_buf; the first
  913.      * character is the one which preceded it before reading in the latest
  914.      * buffer; it needs to be kept around in case it's a newline, so
  915.      * yy_get_previous_state() will have with '^' rules active
  916.      */
  917.  
  918.     yytext = &yy_current_buffer->yy_ch_buf[1];
  919.  
  920.     return ( ret_val );
  921.     }
  922.  
  923.  
  924. /* yy_get_previous_state - get the state just before the EOB char was reached
  925.  *
  926.  * synopsis
  927.  *     yy_state_type yy_get_previous_state();
  928.  */
  929.  
  930. static yy_state_type yy_get_previous_state()
  931.  
  932.     {
  933.     register yy_state_type yy_current_state;
  934.     register YY_CHAR *yy_cp;
  935.  
  936.     register YY_CHAR *yy_bp = yytext;
  937.  
  938.     yy_current_state = yy_start;
  939.     if ( yy_bp[-1] == '\n' )
  940.     ++yy_current_state;
  941.  
  942.     for ( yy_cp = yytext + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp )
  943.     {
  944.     register YY_CHAR yy_c = (*yy_cp ? yy_ec[*yy_cp] : 1);
  945.     if ( yy_accept[yy_current_state] )
  946.         {
  947.         yy_last_accepting_state = yy_current_state;
  948.         yy_last_accepting_cpos = yy_cp;
  949.         }
  950.     while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  951.         {
  952.         yy_current_state = yy_def[yy_current_state];
  953.         if ( yy_current_state >= 94 )
  954.         yy_c = yy_meta[yy_c];
  955.         }
  956.     yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  957.     }
  958.  
  959.     return ( yy_current_state );
  960.     }
  961.  
  962.  
  963. /* yy_try_NUL_trans - try to make a transition on the NUL character
  964.  *
  965.  * synopsis
  966.  *     next_state = yy_try_NUL_trans( current_state );
  967.  */
  968.  
  969. #ifdef YY_USE_PROTOS
  970. static yy_state_type yy_try_NUL_trans( register yy_state_type yy_current_state )
  971. #else
  972. static yy_state_type yy_try_NUL_trans( yy_current_state )
  973. register yy_state_type yy_current_state;
  974. #endif
  975.  
  976.     {
  977.     register int yy_is_jam;
  978.     register YY_CHAR *yy_cp = yy_c_buf_p;
  979.  
  980.     register YY_CHAR yy_c = 1;
  981.     if ( yy_accept[yy_current_state] )
  982.     {
  983.     yy_last_accepting_state = yy_current_state;
  984.     yy_last_accepting_cpos = yy_cp;
  985.     }
  986.     while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
  987.     {
  988.     yy_current_state = yy_def[yy_current_state];
  989.     if ( yy_current_state >= 94 )
  990.         yy_c = yy_meta[yy_c];
  991.     }
  992.     yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
  993.     yy_is_jam = (yy_base[yy_current_state] == 200);
  994.  
  995.     return ( yy_is_jam ? 0 : yy_current_state );
  996.     }
  997.  
  998.  
  999. #ifdef YY_USE_PROTOS
  1000. static void yyunput( YY_CHAR c, register YY_CHAR *yy_bp )
  1001. #else
  1002. static void yyunput( c, yy_bp )
  1003. YY_CHAR c;
  1004. register YY_CHAR *yy_bp;
  1005. #endif
  1006.  
  1007.     {
  1008.     register YY_CHAR *yy_cp = yy_c_buf_p;
  1009.  
  1010.     /* undo effects of setting up yytext */
  1011.     *yy_cp = yy_hold_char;
  1012.  
  1013.     if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  1014.     { /* need to shift things up to make room */
  1015.     register int number_to_move = yy_n_chars + 2; /* +2 for EOB chars */
  1016.     register YY_CHAR *dest =
  1017.         &yy_current_buffer->yy_ch_buf[yy_current_buffer->yy_buf_size + 2];
  1018.     register YY_CHAR *source =
  1019.         &yy_current_buffer->yy_ch_buf[number_to_move];
  1020.  
  1021.     while ( source > yy_current_buffer->yy_ch_buf )
  1022.         *--dest = *--source;
  1023.  
  1024.     yy_cp += dest - source;
  1025.     yy_bp += dest - source;
  1026.     yy_n_chars = yy_current_buffer->yy_buf_size;
  1027.  
  1028.     if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 )
  1029.         YY_FATAL_ERROR( "flex scanner push-back overflow" );
  1030.     }
  1031.  
  1032.     if ( yy_cp > yy_bp && yy_cp[-1] == '\n' )
  1033.     yy_cp[-2] = '\n';
  1034.  
  1035.     *--yy_cp = c;
  1036.  
  1037.     /* note: the formal parameter *must* be called "yy_bp" for this
  1038.      *       macro to now work correctly
  1039.      */
  1040.     YY_DO_BEFORE_ACTION; /* set up yytext again */
  1041.     }
  1042.  
  1043.  
  1044. #ifdef __cplusplus
  1045. static int yyinput()
  1046. #else
  1047. static int input()
  1048. #endif
  1049.  
  1050.     {
  1051.     int c;
  1052.     YY_CHAR *yy_cp = yy_c_buf_p;
  1053.  
  1054.     *yy_cp = yy_hold_char;
  1055.  
  1056.     if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
  1057.     {
  1058.     /* yy_c_buf_p now points to the character we want to return.
  1059.      * If this occurs *before* the EOB characters, then it's a
  1060.      * valid NUL; if not, then we've hit the end of the buffer.
  1061.      */
  1062.     if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] )
  1063.         /* this was really a NUL */
  1064.         *yy_c_buf_p = '\0';
  1065.  
  1066.     else
  1067.         { /* need more input */
  1068.         yytext = yy_c_buf_p;
  1069.         ++yy_c_buf_p;
  1070.  
  1071.         switch ( yy_get_next_buffer() )
  1072.         {
  1073.         case EOB_ACT_END_OF_FILE:
  1074.             {
  1075.             if ( yywrap() )
  1076.             {
  1077.             yy_c_buf_p = yytext + YY_MORE_ADJ;
  1078.             return ( EOF );
  1079.             }
  1080.  
  1081.             YY_NEW_FILE;
  1082.  
  1083. #ifdef __cplusplus
  1084.             return ( yyinput() );
  1085. #else
  1086.             return ( input() );
  1087. #endif
  1088.             }
  1089.             break;
  1090.  
  1091.         case EOB_ACT_CONTINUE_SCAN:
  1092.             yy_c_buf_p = yytext + YY_MORE_ADJ;
  1093.             break;
  1094.  
  1095.         case EOB_ACT_LAST_MATCH:
  1096. #ifdef __cplusplus
  1097.             YY_FATAL_ERROR( "unexpected last match in yyinput()" );
  1098. #else
  1099.             YY_FATAL_ERROR( "unexpected last match in input()" );
  1100. #endif
  1101.         }
  1102.         }
  1103.     }
  1104.  
  1105.     c = *yy_c_buf_p;
  1106.     yy_hold_char = *++yy_c_buf_p;
  1107.  
  1108.     return ( c );
  1109.     }
  1110.  
  1111.  
  1112. #ifdef YY_USE_PROTOS
  1113. void yyrestart( FILE *input_file )
  1114. #else
  1115. void yyrestart( input_file )
  1116. FILE *input_file;
  1117. #endif
  1118.  
  1119.     {
  1120.     yy_init_buffer( yy_current_buffer, input_file );
  1121.     yy_load_buffer_state();
  1122.     }
  1123.  
  1124.  
  1125. #ifdef YY_USE_PROTOS
  1126. void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer )
  1127. #else
  1128. void yy_switch_to_buffer( new_buffer )
  1129. YY_BUFFER_STATE new_buffer;
  1130. #endif
  1131.  
  1132.     {
  1133.     if ( yy_current_buffer == new_buffer )
  1134.     return;
  1135.  
  1136.     if ( yy_current_buffer )
  1137.     {
  1138.     /* flush out information for old buffer */
  1139.     *yy_c_buf_p = yy_hold_char;
  1140.     yy_current_buffer->yy_buf_pos = yy_c_buf_p;
  1141.     yy_current_buffer->yy_n_chars = yy_n_chars;
  1142.     }
  1143.  
  1144.     yy_current_buffer = new_buffer;
  1145.     yy_load_buffer_state();
  1146.  
  1147.     /* we don't actually know whether we did this switch during
  1148.      * EOF (yywrap()) processing, but the only time this flag
  1149.      * is looked at is after yywrap() is called, so it's safe
  1150.      * to go ahead and always set it.
  1151.      */
  1152.     yy_did_buffer_switch_on_eof = 1;
  1153.     }
  1154.  
  1155.  
  1156. #ifdef YY_USE_PROTOS
  1157. void yy_load_buffer_state( void )
  1158. #else
  1159. void yy_load_buffer_state()
  1160. #endif
  1161.  
  1162.     {
  1163.     yy_n_chars = yy_current_buffer->yy_n_chars;
  1164.     yytext = yy_c_buf_p = yy_current_buffer->yy_buf_pos;
  1165.     yyin = yy_current_buffer->yy_input_file;
  1166.     yy_hold_char = *yy_c_buf_p;
  1167.     }
  1168.  
  1169.  
  1170. #ifdef YY_USE_PROTOS
  1171. YY_BUFFER_STATE yy_create_buffer( FILE *file, int size )
  1172. #else
  1173. YY_BUFFER_STATE yy_create_buffer( file, size )
  1174. FILE *file;
  1175. int size;
  1176. #endif
  1177.  
  1178.     {
  1179.     YY_BUFFER_STATE b;
  1180.  
  1181.     b = (YY_BUFFER_STATE) malloc( sizeof( struct yy_buffer_state ) );
  1182.  
  1183.     if ( ! b )
  1184.     YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1185.  
  1186.     b->yy_buf_size = size;
  1187.  
  1188.     /* yy_ch_buf has to be 2 characters longer than the size given because
  1189.      * we need to put in 2 end-of-buffer characters.
  1190.      */
  1191.     b->yy_ch_buf = (YY_CHAR *) malloc( (unsigned) (b->yy_buf_size + 2) );
  1192.  
  1193.     if ( ! b->yy_ch_buf )
  1194.     YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
  1195.  
  1196.     yy_init_buffer( b, file );
  1197.  
  1198.     return ( b );
  1199.     }
  1200.  
  1201.  
  1202. #ifdef YY_USE_PROTOS
  1203. void yy_delete_buffer( YY_BUFFER_STATE b )
  1204. #else
  1205. void yy_delete_buffer( b )
  1206. YY_BUFFER_STATE b;
  1207. #endif
  1208.  
  1209.     {
  1210.     if ( b == yy_current_buffer )
  1211.     yy_current_buffer = (YY_BUFFER_STATE) 0;
  1212.  
  1213.     free( (char *) b->yy_ch_buf );
  1214.     free( (char *) b );
  1215.     }
  1216.  
  1217.  
  1218. #ifdef YY_USE_PROTOS
  1219. void yy_init_buffer( YY_BUFFER_STATE b, FILE *file )
  1220. #else
  1221. void yy_init_buffer( b, file )
  1222. YY_BUFFER_STATE b;
  1223. FILE *file;
  1224. #endif
  1225.  
  1226.     {
  1227.     b->yy_input_file = file;
  1228.  
  1229.     /* we put in the '\n' and start reading from [1] so that an
  1230.      * initial match-at-newline will be true.
  1231.      */
  1232.  
  1233.     b->yy_ch_buf[0] = '\n';
  1234.     b->yy_n_chars = 1;
  1235.  
  1236.     /* we always need two end-of-buffer characters.  The first causes
  1237.      * a transition to the end-of-buffer state.  The second causes
  1238.      * a jam in that state.
  1239.      */
  1240.     b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
  1241.     b->yy_ch_buf[2] = YY_END_OF_BUFFER_CHAR;
  1242.  
  1243.     b->yy_buf_pos = &b->yy_ch_buf[1];
  1244.  
  1245.     b->yy_eof_status = EOF_NOT_SEEN;
  1246.     }
  1247.  
  1248.  
  1249. #ifdef __BORLANDC__
  1250. #pragma option -w
  1251. #endif
  1252.  
  1253. /**************************************************************************/
  1254. /* global variables                                                       */
  1255. /**************************************************************************/
  1256. int cmdtoken;         /* first token in each batch line */
  1257. int errorcount=0;     /* syntax error counter */
  1258. int errorlevelflag=0; /* control use of "set errorlevel=$status" */
  1259. int indentlevel=0;    /* indent level of output */
  1260.  
  1261. /**************************************************************************/
  1262. /* support functions                                                      */
  1263. /**************************************************************************/
  1264. /* report any errors */
  1265. int reporterrors()
  1266. {
  1267.     char s[7];
  1268.  
  1269.     if (errorcount) {
  1270.         itoa(errorcount, s, 10);
  1271.         fputs("\n\nNUMBER OF ERRORS = ", stderr);
  1272.         fputs(s, stderr);
  1273.         fputs("\n\n", stderr);
  1274.         return EXIT_FAILURE;
  1275.     }
  1276.     return EXIT_SUCCESS;
  1277. }
  1278.  
  1279. /* abnormal termination */
  1280. void terminate(void)
  1281. {
  1282.     putln();
  1283.     puts(" ### PREMATURE END-OF-FILE ###");
  1284.     errorcount++;
  1285.     exit(reporterrors());
  1286. }
  1287.  
  1288. /* wrapper for yylex */
  1289. int lex(void)
  1290. {
  1291.     int result;         /* return result */
  1292.     static int count=0; /* count number of times yylex returns 0 */
  1293.     
  1294.     result = yylex();
  1295.     if (!result) {
  1296.         if (count==1) {
  1297.             terminate();
  1298.         } else {    /* handle possible premature eof */
  1299.             count++;
  1300.             result = EOL;
  1301.         }
  1302.     }
  1303.     return result;
  1304. }
  1305.  
  1306. /* indent output based on global indentlevel */
  1307. void indent(void)
  1308. {
  1309.     int i;
  1310.     
  1311.     for (i=0; i<indentlevel; i++) puttab();
  1312. }
  1313.  
  1314. /* put token back to input stream */
  1315. /* note: flex 2.3.7 yyless(0) not available in section 3 */
  1316. void putbacktoken(void)
  1317. {
  1318.     int i;
  1319.  
  1320.     for (i=yyleng-1; i>=0; i--) {
  1321.         unput(yytext[i]);
  1322.     }
  1323. }
  1324.  
  1325. /* translate character in string s */
  1326. char *tr(char *s, int oldch, int newch)
  1327. {
  1328.     char *sp = s;
  1329.  
  1330.     do {
  1331.         if (*sp==oldch) *sp=newch;
  1332.     } while (*sp++);
  1333.     return s;
  1334. }
  1335.  
  1336. /* convert replaceable parameter, e.g. %1 -> $1 */
  1337. char *cvt_parameter(char *s)
  1338. {
  1339.     strcpy(textbuf, s);
  1340.     *textbuf='$';
  1341.     return textbuf;
  1342. }
  1343.  
  1344. /* convert variable, e.g. %PATH% -> ${path} */
  1345. char *cvt_variable(char *s)
  1346. {
  1347.     char *sp;
  1348.  
  1349.     strcpy(textbuf, "${");
  1350.     sp = s;
  1351.     sp++;
  1352.     strncat(textbuf, sp, yyleng-2);
  1353.     strcat(textbuf, "}");
  1354.     return strlwr(textbuf);
  1355. }
  1356.  
  1357. /* convert variable used with 'for' keyword, e.g. %%F -> ${f} */
  1358. char *cvt_for_variable(char *s)
  1359. {
  1360.     char *sp;
  1361.  
  1362.     strcpy(textbuf, "${");
  1363.     sp = s;
  1364.     sp += 2;
  1365.     strncat(textbuf, sp, yyleng-2);
  1366.     strcat(textbuf, "}");
  1367.     return strlwr(textbuf);
  1368. }
  1369.  
  1370. /* convert variable used with set keyword, e.g. ${f} -> f */ 
  1371. char *cvt_set_variable(int token)
  1372. {
  1373.     int len;
  1374.  
  1375.     switch(token) {
  1376.     case VARIABLE:
  1377.     case FOR_VARIABLE:
  1378.         len = strlen(textbuf)-2;
  1379.         memmove(textbuf, textbuf+2, len);
  1380.         textbuf[len-1]='\0';
  1381.         break;
  1382.     default:
  1383.         break;
  1384.     }
  1385.     return textbuf;
  1386. }
  1387.  
  1388. /* convert from batch format to csh format */
  1389. char *cvt_token(int token, char *s)
  1390. {
  1391.     char *sp, *tp=textbuf;
  1392.  
  1393.     switch(token) {
  1394.     case PARAMETER:
  1395.         if (s) cvt_parameter(s);
  1396.         else   cvt_parameter(yytext);
  1397.         break;
  1398.     case VARIABLE:
  1399.         if (s) cvt_variable(s);
  1400.         else   cvt_variable(yytext);
  1401.         break;
  1402.     case FOR_VARIABLE:
  1403.         if (s) cvt_for_variable(s);
  1404.         else   cvt_for_variable(yytext);
  1405.         break;
  1406.     case SPACE:
  1407.         if (s) strcpy(textbuf, s);
  1408.         else   strcpy(textbuf, yytext);
  1409.         /* translate delimiter if set or path */
  1410.         if (cmdtoken==INIT_SET || cmdtoken==INIT_PATH)
  1411.             tr(textbuf, ';', ' ');
  1412.         break;
  1413.     default:
  1414.         if (s) strcpy(textbuf, s);
  1415.         else   strcpy(textbuf, yytext);
  1416.         tr(textbuf, '/', '-');      /* translate options specifier */
  1417.         tr(textbuf, '\\', '/');     /* translate directory separator */
  1418.         sp = strchr(textbuf, ':');  /* skip over drive specifier */
  1419.         if (sp) { 
  1420.             tp = ++sp;
  1421.         }
  1422.         /* convert to lower case unless remark or echo */
  1423.         if (!(cmdtoken==INIT_REM || cmdtoken==INIT_ECHO) || 
  1424.               strchr(tp, '/') || strchr(textbuf, ':')) {
  1425.             strlwr(tp);
  1426.         }
  1427.         break;
  1428.     }
  1429.     return tp;
  1430. }
  1431.  
  1432. /* print text associated with remaining tokens on line */
  1433. void puttokln(int token, char *start, char *end)
  1434. {
  1435.    char *tp;
  1436.  
  1437.    BEGIN(TEXT);
  1438.    ckeol(token);
  1439.    if (start) {
  1440.         tp = cvt_token(token, start);
  1441.         /* translate names of common commands */
  1442.         if (!strcmp(tp, "chdir")) strcpy(tp, "cd");
  1443.         else if (!strcmp(tp, "cls")) strcpy(tp, "clear");
  1444.         else if (!strcmp(tp, "command")) strcpy(tp, "csh");
  1445.         else if (!strcmp(tp, "copy")) strcpy(tp, "cp");
  1446.         else if (!strcmp(tp, "del")) strcpy(tp, "rm");
  1447.         else if (!strcmp(tp, "dir")) strcpy(tp, "ls");
  1448.         else if (!strcmp(tp, "erase")) strcpy(tp, "rm");
  1449.         else if (!strcmp(tp, "md")) strcpy(tp, "mkdir");
  1450.         else if (!strcmp(tp, "move")) strcpy(tp, "mv");
  1451.         else if (!strcmp(tp, "print")) strcpy(tp, "pr");
  1452.         else if (!strcmp(tp, "rd")) strcpy(tp, "rmdir");
  1453.         else if (!strcmp(tp, "ren")) strcpy(tp, "mv");
  1454.         else if (!strcmp(tp, "rename")) strcpy(tp, "mv");
  1455.         else if (!strcmp(tp, "time")) strcpy(tp, "date");
  1456.         else if (!strcmp(tp, "type")) strcpy(tp, "cat");
  1457.         else if (!strcmp(tp, "xcopy /s")) strcpy(tp, "cp -r");
  1458.         else if (!strcmp(tp, "xcopy")) strcpy(tp, "cp");
  1459.         putstr(tp);
  1460.    }
  1461.    while ((token=lex())!=EOL) {
  1462.        putstr(cvt_token(token, NULL));
  1463.    }
  1464.    if (end) {
  1465.        putstr(end);
  1466.    }
  1467.    putln();
  1468. }
  1469.  
  1470. /* eat remainder of line */
  1471. void eattokens(void)
  1472. {
  1473.    BEGIN(TEXT);
  1474.    while (lex()!=EOL) ;
  1475. }
  1476.  
  1477. /**************************************************************************/
  1478. /* batch keyword functions                                                */
  1479. /**************************************************************************/
  1480. void kw_call(void)
  1481. {
  1482.     errorlevelflag=0;
  1483.     indent();
  1484.     puttokln(INIT_CALL, "csh ", NULL);
  1485. }
  1486.  
  1487. void kw_command(void)
  1488. {
  1489.     int token;
  1490.  
  1491.     errorlevelflag=0;
  1492.     putbacktoken();
  1493.     BEGIN(TEXT);
  1494.     token = lex();
  1495.     indent();
  1496.     puttokln(token, yytext, NULL);
  1497. }
  1498.  
  1499. void kw_echo(void)
  1500. {
  1501.     int token;
  1502.     
  1503.     BEGIN(ECHOS);
  1504.     token = lex();
  1505.     switch(token) {
  1506.     case ECHO_ON:
  1507.         eattokens();
  1508.         break;
  1509.     case ECHO_OFF:
  1510.         eattokens();
  1511.         break;
  1512.     case ECHO_DOT:
  1513.         indent();
  1514.         puts("echo ''");
  1515.         eattokens();
  1516.         break;
  1517.     case EOL:
  1518.         break;
  1519.     default:
  1520.         indent();
  1521.         putstr("echo ");
  1522.         putbacktoken();
  1523.         puttokln(INIT_ECHO, NULL, NULL);
  1524.         break;
  1525.     }
  1526. }
  1527.  
  1528. void kw_for(void)
  1529. {
  1530.     int token;
  1531.     
  1532.     BEGIN(FOR);
  1533.     indent();
  1534.     putstr("foreach ");
  1535.  
  1536.     /* get variable */
  1537.     token = lex();
  1538.     ckeol(token);
  1539.     cktok(token, FOR_VARIABLE);
  1540.     if (yyleng>2) putstr(yytext+2);
  1541.  
  1542.     /* check for "in" keyword */
  1543.     token = lex();
  1544.     ckeol(token);
  1545.     cktok(token, FOR_IN);
  1546.     putstr(" ");
  1547.  
  1548.     /* get wordlist */
  1549.     token = lex();
  1550.     ckeol(token);
  1551.     cktok(token, FOR_WORDLIST);
  1552.     putstr(yytext);
  1553.  
  1554.     /* check for "do" keyword */
  1555.     token = lex();
  1556.     ckeol(token);
  1557.     cktok(token, FOR_DO);
  1558.     putln();
  1559.  
  1560.     /* process command */
  1561.     indentlevel++;
  1562.     if (dispatch()==EOF) terminate();
  1563.     indentlevel--;
  1564.  
  1565.     /* end foreach */
  1566.     indent();
  1567.     puts("end");
  1568. }
  1569.  
  1570. void kw_goto(void)
  1571. {
  1572.     indent();
  1573.     puttokln(INIT_GOTO, yytext, NULL);
  1574. }
  1575.  
  1576. void kw_if(void)
  1577. {
  1578.     int token;
  1579.     int not = 0;
  1580.     char *sp, strbuf[STRBUFSIZE];
  1581.  
  1582.     BEGIN(TEXT);
  1583.     for (;;) {
  1584.         while ((token=lex())==SPACE) ;
  1585.         ckeol(token);
  1586.         switch (token) {
  1587.         case IF_NOT:
  1588.             not = !not;
  1589.             continue;
  1590.         case IF_ERRORLEVEL:
  1591.             if (errorlevelflag==0) {
  1592.                 errorlevelflag=1;
  1593.                 indent();
  1594.                 puts("set errorlevel=$status");
  1595.             }
  1596.             while ((token=lex())==SPACE) ;
  1597.             ckeol(token);
  1598.             indent();
  1599.             if (not) {
  1600.                 putstr("if (${errorlevel} < ");
  1601.             } else {
  1602.                 putstr("if (${errorlevel} >= ");
  1603.             }
  1604.             do {
  1605.                 putstr(cvt_token(token, NULL));
  1606.             } while (!((token=lex())==SPACE||token==EOL));
  1607.             break;
  1608.         case IF_EXIST:
  1609.             while ((token=lex())==SPACE) ;
  1610.             indent();
  1611.             if (not) {
  1612.                 putstr("if (! ");
  1613.             } else {
  1614.                 putstr("if (");
  1615.             }
  1616.             ckeol(token);
  1617.             /* get file or directory name */
  1618.             strcpy(strbuf, "");
  1619.             do {
  1620.                 strcat(strbuf, cvt_token(token, NULL));
  1621.             } while (!((token=lex())==SPACE||token==EOL));
  1622.             sp = strstr(strbuf, "/nul");
  1623.             if (sp && sp==strbuf+strlen(strbuf)-4) { /* directory */
  1624.                 putstr("-d \"");
  1625.                 *sp = '\0';
  1626.             } else {       /* file */
  1627.                 putstr("-f \"");
  1628.             }
  1629.             /* print file or directory name */
  1630.             putstr(strbuf);
  1631.             putstr("\"");
  1632.             break;
  1633.         default:    /* must be string comparison */
  1634.             indent();
  1635.             putstr("if (");
  1636.             do {
  1637.                 putstr(cvt_token(token, NULL));
  1638.             } while (!((token=lex())==SPACE||token==EOL));
  1639.             if (not) {
  1640.                 putstr(" != ");
  1641.             } else {
  1642.                 putstr(" == ");
  1643.             }
  1644.             ckeol(token);
  1645.             while ((token=lex())==SPACE) ;
  1646.             ckeol(token);
  1647.             do {
  1648.                 putstr(cvt_token(token, NULL));
  1649.             } while (!((token=lex())==SPACE||token==EOL));
  1650.             break;
  1651.         }
  1652.     break;
  1653.     }
  1654.     putstr(")");
  1655.     ckeol(token);
  1656.     puts(" then");
  1657.  
  1658.     /* process command */
  1659.     indentlevel++;
  1660.     if (dispatch()==EOF) terminate();
  1661.     indentlevel--;
  1662.  
  1663.     /* end if */
  1664.     indent();
  1665.     puts("endif");
  1666. }
  1667.  
  1668. void kw_label(void)
  1669. {
  1670.     strcpy(textbuf, yytext+1);
  1671.     strcat(textbuf, ":");
  1672.     puts(strlwr(textbuf));
  1673.     eattokens();
  1674. }
  1675.  
  1676. void kw_ln(void)
  1677. {
  1678.     putln();
  1679. }
  1680.  
  1681. void kw_path(void)
  1682. {
  1683.     int token;
  1684.  
  1685.     BEGIN(TEXT);
  1686.     while ((token=lex())==SPACE) ;
  1687.     indent();
  1688.     if (token==EOL) {
  1689.         putstr("unset path");
  1690.         putln();
  1691.     } else {
  1692.         putstr("set path=(");
  1693.         puttokln(token, yytext, ")");
  1694.     }
  1695.     indent();
  1696.     puts("rehash");
  1697. }
  1698.  
  1699. void kw_pause(void)
  1700. {
  1701.     indent();
  1702.     puts("echo -n 'Press the Enter key to continue...'");
  1703.     indent();
  1704.     puts("echo -n $?");
  1705.     eattokens();
  1706. }
  1707.  
  1708. void kw_remark(void)
  1709. {
  1710.     puttokln(INIT_REM, "#", NULL);
  1711. }
  1712.  
  1713. void kw_set(void)
  1714. {
  1715.     int token;
  1716.  
  1717.     BEGIN(TEXT);
  1718.     while ((token=lex())==SPACE) ;
  1719.     if (token==EOL) { 
  1720.        indent();
  1721.        puts("set"); 
  1722.        return;
  1723.     }
  1724.     cvt_token(token, NULL);
  1725.     cvt_set_variable(token);
  1726.     if (!stricmp(textbuf, "path")) {
  1727.         kw_path();
  1728.         return;
  1729.     }
  1730.  
  1731.     /* variable name in textbuf, variable contents in yytext */
  1732.     while ((token=lex())==SPACE) ;
  1733.     indent();
  1734.     if (token==EOL) {
  1735.         putstr("unset ");
  1736.         putstr(textbuf);
  1737.         putln();
  1738.     } else {
  1739.         putstr("set ");
  1740.         putstr(textbuf);
  1741.         putstr("=\"");
  1742.         puttokln(token, yytext, "\"");
  1743.     }
  1744. }
  1745.  
  1746. void kw_shift(void)
  1747. {
  1748.     indent();
  1749.     puttokln(INIT_SHIFT, "shift ", NULL);
  1750. }
  1751.  
  1752. /**************************************************************************/
  1753. /* keyword function table                                                 */
  1754. /**************************************************************************/
  1755. FNTBL fntbl[] =
  1756. {
  1757.         {token(INIT_CALL),    kw_call},
  1758.         {token(INIT_COMMAND),    kw_command},
  1759.         {token(INIT_ECHO),    kw_echo},
  1760.         {token(INIT_FOR),    kw_for},
  1761.         {token(INIT_GOTO),    kw_goto},
  1762.         {token(INIT_IF),    kw_if},
  1763.         {token(INIT_LABEL),    kw_label},
  1764.         {token(EOL),        kw_ln},
  1765.         {token(INIT_PATH),    kw_path},
  1766.         {token(INIT_PAUSE),    kw_pause},
  1767.         {token(INIT_REM),    kw_remark},
  1768.         {token(INIT_SET),    kw_set},
  1769.         {token(INIT_SHIFT),    kw_shift}
  1770. };
  1771.  
  1772. #define N_FNTBL sizeof(fntbl)/sizeof(fntbl[0])
  1773.  
  1774. /**************************************************************************/
  1775. /* function dispatcher                                                    */
  1776. /**************************************************************************/
  1777. int dispatch(void) /* returns 0=success; EOF=end of file */
  1778. {
  1779.     int i, token;
  1780.  
  1781.     BEGIN(INITIAL);
  1782.     token = yylex();
  1783.     if (token) {
  1784.         for (i = 0; i < N_FNTBL; i++) {
  1785.             if (token == fntbl[i].token) {
  1786.                 cmdtoken = token;
  1787.                 fntbl[i].fn();
  1788.                 return 0;
  1789.             }
  1790.         }
  1791.  
  1792.         /* no match, call kw_command() */
  1793.         cmdtoken = INIT_COMMAND;
  1794.         kw_command();
  1795.         return 0;
  1796.     }
  1797.     return EOF;
  1798. }
  1799.  
  1800. /**************************************************************************/
  1801. /* main function                                                          */
  1802. /**************************************************************************/
  1803. int main()
  1804. {
  1805.     puts("#! /bin/csh");
  1806.     while (dispatch()!=EOF) ;
  1807.     return reporterrors();
  1808. }
  1809.